package com.dzl.movie;

import com.dzl.base.controller.BaseController;
import com.dzl.config.exception.CommonException;
import com.dzl.moive.pojo.WelfareMovieCinema;
import com.dzl.moive.pojo.WelfareMovieInfo;
import com.dzl.moive.pojo.query.WelfareMovieCinemaQuery;
import com.dzl.moive.pojo.vo.WelfareMovieCinemaVo;
import com.dzl.moive.pojo.vo.WelfareMovieTicketVo;
import com.dzl.moive.service.WelfareMovieCinemaService;
import com.dzl.util.EmptyUtils;
import com.dzl.util.JsonResult;
import com.dzl.util.PageUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 电影院信息(welfare_movie_cinema)表控制层
 * @author liuguanjun
 * @date 2021-11-03 10:46
 */
@RestController
@RequestMapping("/welfareMovieCinema")
public class WelfareMovieCinemaController extends BaseController {

    @Autowired
    private WelfareMovieCinemaService service;


    /**
     * 电影院列表分页查询
     * @date 2021/11/03 10:46
     * @author liuguanjun
     * @param query 查询条件
     */
    @GetMapping("/queryMovieCinemaListPage")
    public PageUtils<WelfareMovieCinemaVo> getWelfareMovieCinemaVoListPage(WelfareMovieCinemaQuery query) {
        if(EmptyUtils.isEmpty(query.getCitycode())){
            throw new CommonException("缺少参数:城市编码[citycode]");
        }
        if(EmptyUtils.isEmpty(query.getLat())){
            throw new CommonException("缺少参数:当前地址纬度[lat]");
        }
        if(EmptyUtils.isEmpty(query.getLon())){
            throw new CommonException("缺少参数:当前地址经度[lon]");
        }
        PageInfo<WelfareMovieCinemaVo> pageInfo = service.getWelfareMovieCinemaVoListPage(query);
        return new PageUtils<>(pageInfo);
    }

    /**
     * 查询影片开放购票的影院
     * @param query citycode 城市编码等字段
     * @author liuguanjun
     * @date 2021-11-03 14:33:50
     **/
    /*@GetMapping(value = "queryMoviePlayCinemaList")
    public JsonResult<List<WelfareMovieCinemaVo>> getWelfareMoviePlayCinemaVoList(WelfareMovieCinemaQuery query) {
        if(EmptyUtils.isEmpty(query.getCitycode())){
            return JsonResult.failWithMsg("缺少参数:城市编码[citycode]");
        }
        if(EmptyUtils.isEmpty(query.getLat())){
            throw new CommonException("缺少参数:当前地址纬度[lat]");
        }
        if(EmptyUtils.isEmpty(query.getLon())){
            throw new CommonException("缺少参数:当前地址经度[lon]");
        }
        if(EmptyUtils.isEmpty(query.getMovieid())){
            throw new CommonException("缺少参数:电影id[movieid]");
        }
        return JsonResult.success(service.getWelfareMoviePlayCinemaVoList(query));
    }
*/


    /**
     * 获取电影院详情
     * @param cinemaid 电影院id
     * @param movieid 电影id
     * @param playdate 选择日期
     * @author liuguanjun
     * @date 2021-11-03 15:25:50
     **/
    @GetMapping(value = "getMovieCinemaDetail")
    public JsonResult<WelfareMovieCinema> getMovieCinemaDetail(Integer cinemaid, Integer movieid, String playdate) {
        if(EmptyUtils.isEmpty(cinemaid)){
            return JsonResult.failWithMsg("缺少参数:电影院id[cinemaid]");
        }
        return JsonResult.success(service.getMovieCinemaDetail(cinemaid,movieid,playdate));
    }

    /**
     * 获取排片详情及排片座位图
     * @param opiid 排片id
     * @author liuguanjun
     * @date 2021-11-02 16:12:50
     **/
    @GetMapping(value = "getMovieTicketDetail")
    public JsonResult<WelfareMovieTicketVo> getMovieTicketDetail(String opiid) {
        if(EmptyUtils.isEmpty(opiid)){
            return JsonResult.failWithMsg("缺少参数:排片id[opiid]");
        }
        WelfareMovieTicketVo welfareMovieTicketVo = service.getWelfareMovieTicket(opiid);
        if(EmptyUtils.isNotEmpty(welfareMovieTicketVo)){
            return JsonResult.success(welfareMovieTicketVo);
        }else{
            return JsonResult.failWithMsg("该场次已下线");
        }
    }


}
